const S_OFFSET_X = 69;
const S_OFFSET_Y = 98;
const A_OFFSET_X = 20;
const A_OFFSET_Y = 40;
import work from './image/1.png';
import goods from './image/5.png';
import lockLoc from './image/6.png';
import lockAndGoods from './image/4.png';
import remnant from './image/7.png';
import aa from './image/8.png';
import ma from './image/9.png';
import goodsTurnover from './image/10.png';
import pallet from './image/11.png';
import lockAndPallet from './image/12.png';

import bondedGoods from './image/bondedGoods.png';
import bondedPledge from './image/bondedPledge.png';
import generalCargo from './image/generalCargo.png';
import ordinaryPledge from './image/ordinaryPledge.png';
import stacker from './image/stacker.png';
import workbench from './image/workbench.png';
import threadBody from './image/threadBody.png';
import close from './image/close.png';
import tunnel from './image/tunnel.png';
import otherEquipment from './image/otherEquipment.png';
import location from './image/location.png';
import AGV from './image/AGV.png';
import AGV2Up from './image/AGV2.png';
import AGV2Right from './image/AGV2-right.png';
import AGV2Down from './image/AGV2-down.png';
import AGV2Left from './image/AGV2-left.png';

export default {
    getLocTypeName(locType) {
        let name = '';
        switch (locType) {
            case 'ever_error':
                name = '永久锁';
                break;
            case 'point_error':
                name = '库位异常锁';
                break;
            case 'goods_error':
                name = '货物异常锁';
                break;
            case 'other_error':
                name = '其他锁';
                break;
            default:
                name = '';
        }
        return name;
    },

    getImage() {
        return {
            work: {
                src: null,
                img: work
            },
            goods: {
                src: null,
                img: goods
            },
            pallet: {
                src: null,
                img: pallet
            },
            lockLoc: {
                src: null,
                img: lockLoc
            },
            lockAndGoods: {
                src: null,
                img: lockAndGoods
            },
            lockAndPallet: {
                src: null,
                img: lockAndPallet
            },
            remnant: {
                src: null,
                img: remnant
            },
            goodsTurnover: {
                src: null,
                img: goodsTurnover
            },
            ma: {
                src: null,
                img: ma
            },
            aa: {
                src: null,
                img: aa
            },
            bondedGoods: {
                src: null,
                img: bondedGoods
            },
            bondedPledge: {
                src: null,
                img: bondedPledge
            },
            generalCargo: {
                src: null,
                img: generalCargo
            },
            ordinaryPledge: {
                src: null,
                img: ordinaryPledge
            },
            stacker: {
                src: null,
                img: stacker
            },
            workbench: {
                src: null,
                img: workbench
            },
            AGV: {
                src: null,
                img: AGV
            },
            AGV2Up: {
                src: null,
                img: AGV2Up
            },
            AGV2Right: {
                src: null,
                img: AGV2Right
            },
            AGV2Down: {
                src: null,
                img: AGV2Down
            },
            AGV2Left: {
                src: null,
                img: AGV2Left
            },
            threadBody: {
                src: null,
                img: threadBody
            },
            otherEquipment: {
                src: null,
                img: otherEquipment
            },
            tunnel: {
                src: null,
                img: tunnel
            },
            close: {
                src: null,
                img: close
            },
            location: {
                src: null,
                img: location
            }
        };
    },

    isTrue(data) {
        return !!data;
    },

    hanleXY(type, interval, cooX, cooY) {
        let x = 0;
        let y = 0;
        if (type === 'S') {
            x = Math.abs((cooX - S_OFFSET_X) * interval);
            y = Math.abs((cooY - S_OFFSET_Y) * interval);
            return {
                x: x,
                y: y
            };
        } else if (type === 'A') {
            x = Math.abs((cooX - A_OFFSET_X) * interval); // 15
            y = Math.abs((cooY - A_OFFSET_Y)  * interval); // 100
            return {
                x: x,
                y: y
            };
        } else {
            x = Math.abs(cooX * interval * 1.5) + 10;
            y = Math.abs(cooY * interval * 1.5) + 10;
            return {
                x: y,
                y: x
            };
        }
    },

    // 存储区处理
    hanleStgXY(mapType, list, interval) {
        let xList = [];
        let yList = [];
        let width = interval + 2;
        let height = 0;
        list.forEach(item => {
            xList.push(item.cooX);
            yList.push(item.cooY);
        });
        height = xList.length * interval + (xList.length - 1) * 7;
        let body = {};
        if (mapType === 'A') {
            body = {
                x: (Math.abs(Math.min(...xList) - A_OFFSET_X)) * interval - 1,
                y: (Math.abs(Math.min(...yList) - A_OFFSET_Y)) * interval - 1,
                width: width,
                height: height,
                alleyCode: list[0].alleyCode,
                len: list.length
            };
        } else {
            body = {
                x: (Math.abs(Math.min(...xList) - S_OFFSET_X)) * interval - 1,
                y: (Math.abs(Math.min(...yList) - S_OFFSET_Y)) * interval - 1,
                width: height,
                height: width,
                alleyCode: list[0].alleyCode,
                len: list.length
            };
        }
        return body;
    },

    hanleStgXYGet(mapType, x, y, interval, len) {
        let width = interval + 2;
        let height = len * interval + (len - 1) * 7;
        let body = {};
        if (mapType === 'A') {
            body = {
                x: Math.abs(x - A_OFFSET_X) * interval - 1,
                y: Math.abs(y - A_OFFSET_Y) * interval - 1,
                width: width,
                height: height,
                len: len
            };
        } else {
            body = {
                x: Math.abs(x - S_OFFSET_X) * interval - 1,
                y: Math.abs(y - S_OFFSET_Y) * interval - 1,
                width: height,
                height: width,
                len: len
            };
        }
        return body;
    },

    judgeFill(type) {
        let fill = '#fff';
        let stroke = '#959595';
        switch (type) {
            case 'P':
                fill = '#fff';
                stroke = '#959595';
                break;
            case 'R': // 通道
                fill = 'rgb(158, 199, 220)';
                stroke = '#fff';
                break;
            case 'C':
                fill = '#a7ffec';
                stroke = '#fff';
                break;
            case 'B':
                fill = 'rgb(182,186,194)';
                stroke = '#fff';
                break;
            case 'OUT_WORK_STATION':
            case 'IN_WORK_STATION':
                fill = '#273bff';
                stroke = '#fff';
                break;
            case 'L':
                fill = '#ff9218';
                stroke = '#fff';
                break;
            case 'T':
                fill = '#fff9bc';
                stroke = '#fff';
                break;
            default:
                fill = '#fff';
                stroke = '#959595';
                break;
        }
        return {
            fill,
            stroke
        };
    },
    handleMapData(list, key) {
        let obj = {};
        for (let i = 0, len = list.length; i < len; i++) {
            obj[list[i][key]] = list[i];
        }
        return obj;
    },

    arrToObj(arr) {
        let obj = {};
        for (let i = 0, len = arr.length; i < len; i++) {
            let key = arr[i]['locCode'] + ',' + arr[i]['alleyCode'];
            obj[key] = arr[i];
        }
        return obj;
    },

    objToArr(obj) {
        let arr = [];
        if (Object.keys(obj).length) {
            for (let item in obj) {
                arr.push(obj[item]);
            }
        }
        return arr;
    }
};
